import request from '@/utils/request'

// ========== 知识库管理 API ==========

// 查询知识库列表
export function listKnowledgeBase(query) {
  return request({
    url: '/api/ai/knowledgebase/list',
    method: 'get',
    params: query
  })
}

// 查询知识库详细
export function getKnowledgeBase(knowledgeBaseId) {
  return request({
    url: '/api/ai/knowledgebase/' + knowledgeBaseId,
    method: 'get'
  })
}

// 新增知识库
export function addKnowledgeBase(data) {
  return request({
    url: '/api/ai/knowledgebase',
    method: 'post',
    data: data
  })
}

// 删除知识库
export function delKnowledgeBase(knowledgeBaseId) {
  return request({
    url: '/api/ai/knowledgebase/' + knowledgeBaseId,
    method: 'delete'
  })
}

// 批量删除知识库
export function delKnowledgeBaseBatch(knowledgeBaseIds) {
  return request({
    url: '/api/ai/knowledgebase',
    method: 'delete',
    params: { knowledgeBaseIds: knowledgeBaseIds }
  })
}

// 获取可用知识库列表
export function getAvailableKnowledgeBases() {
  return request({
    url: '/api/ai/knowledgebase/available',
    method: 'get'
  })
}

// 查询索引下的文档列表
export function listIndexDocuments(params) {
  return request({
    url: '/api/ai/knowledgebase/listIndexDocuments',
    method: 'get',
    params: params
  })
}

// 查询索引下的文档详情列表
export function listIndexFileDetails(params) {
  return request({
    url: '/api/ai/knowledgebase/listIndexFileDetails',
    method: 'get',
    params: params
  })
}

// 删除索引下的文档
export function deleteIndexDocument(data) {
  return request({
    url: '/api/ai/knowledgebase/deleteIndexDocument',
    method: 'delete',
    data: data
  })
}

// 提交索引任务
export function submitIndexJob(indexId) {
  return request({
    url: '/api/ai/knowledgebase/submitIndexJob/' + indexId,
    method: 'post'
  })
}

// 获取索引任务状态
export function getIndexJobStatus(indexId, jobId) {
  return request({
    url: '/api/ai/knowledgebase/getIndexJobStatus/' + indexId + '/' + jobId,
    method: 'get'
  })
}

// 提交索引添加文档任务
export function submitIndexAddDocumentsJob(data) {
  return request({
    url: '/api/ai/knowledgebase/submitIndexAddDocumentsJob',
    method: 'post',
    data: data
  })
}

// ========== 文档管理 API ==========

// 查询文档列表
export function listChunks(params) {
  return request({
    url: '/api/ai/document/chunks',
    method: 'get',
    params: params
  })
}

// 更新文档块
export function updateChunk(data) {
  return request({
    url: '/api/ai/document/chunk',
    method: 'put',
    data: data
  })
}

// 删除文档块
export function deleteChunks(data) {
  return request({
    url: '/api/ai/document/chunks',
    method: 'delete',
    data: data
  })
}

// 查询文档列表
export function listDocument(params) {
  return request({
    url: '/api/ai/document/list',
    method: 'get',
    params: params
  })
}

// 查询文档详细
export function getDocument(fileId) {
  return request({
    url: '/api/ai/document/' + fileId,
    method: 'get'
  })
}

// 新增文档
export function addDocument(data) {
  return request({
    url: '/api/ai/document',
    method: 'post',
    data: data
  })
}

// 删除文档
export function delDocument(fileId) {
  return request({
    url: '/api/ai/document/' + fileId,
    method: 'delete'
  })
}

// 批量删除文档
export function delDocumentBatch(fileIds) {
  return request({
    url: '/api/ai/document',
    method: 'delete',
    params: { fileIds: fileIds }
  })
}

// 申请上传凭证
export function applyUploadLease(params) {
  return request({
    url: '/api/ai/document/apply-upload-lease',
    method: 'get',
    params: params
  })
}

// 更新文档标签
export function updateDocumentTags(fileId, tags) {
  return request({
    url: '/api/ai/document/' + fileId + '/tags',
    method: 'put',
    data: { tags: tags }
  })
}

// 从OSS导入文件
export function importFromOss(data) {
  return request({
    url: '/api/ai/document/import-from-oss',
    method: 'post',
    data: data
  })
}

// ========== 类目管理 API ==========

// 查询类目列表
export function listCategory(data) {
  return request({
    url: '/api/ai/category',
    method: 'get',
    data: data
  })
}

// 新增类目
export function addCategory(data) {
  return request({
    url: '/api/ai/category',
    method: 'post',
    data: data
  })
}

// 删除类目
export function delCategory(categoryId) {
  return request({
    url: '/api/ai/category/' + categoryId,
    method: 'delete'
  })
}

// 批量删除类目
export function delCategoryBatch(categoryIds) {
  return request({
    url: '/api/ai/category',
    method: 'delete',
    params: { categoryIds: categoryIds }
  })
}